<?php
require_once 'models/client.inc';

/**
 * @author dkrasilnikov@gmail.com
 * @orm.table show_mode(mid)
 * @orm.key Id
 */
class TMSShowMode extends TNOrmObject {
/**
 * @var int
 * @orm.scalar mid
 */	
	public $Id;
/**
 * @var string
 * @orm.scalar code
 */	
	public $Code;
	
	public function __toString(){
		return $this->Code;
	}
}

/**
 * @author dkrasilnikov@gmail.com
 * @orm.table category(cid)
 * @orm.key Id
 * @orm.nestedset Parent SubCategories
 * 
 * @property TMSCategory $Parent 
 * @property TMSPage $Info {@orm.reference Id(info_page)}
 * @property TMSPage $Pages {@orm.collection TMSCategoryPageAssociation.Page Category(cid)}
 * @property TMSShowMode $Mode {@orm.reference Id(mode)}
 */
class TMSCategory extends TNOrmObject {
/**
 * @var int
 * @orm.scalar cid
 */	
	public $Id;
/**
 * @var string
 * @orm.scalar lang
 */	
	public $Language;
/**
 * @var string
 * @orm.scalar name
 */	
	public $Name;
/**
 * @var string
 * @orm.scalar slug
 */	
	public $Slug;

/**
 * @var int
 * @orm.scalar ordernum
 */	
	public $OrderNumber;
	
/**
 * @var bool
 * @orm.scalar is_published
 */	
	public $IsPublished;
	
/**
 * @var TMSPage[]
 */	
	protected $_orm_pages_;	
	
/**
 * @var TMSShowMode
 */	
	protected $_orm_mode_;

/**
 * @var TMSPage
 */	
	protected $_orm_info_;
	
	protected $_ns_parent_;
	
	public $SubCategories = array();
	
	public function __toString(){
		return $this->Name;
	}
}


/**
 * @author dkrasilnikov@gmail.com
 * @orm.table comment(comment_id)
 * @orm.key Id
 * 
 * @property TMSUser $Author {@orm.reference Id(author)}
 * @property TMSUser $ApprovedBy {@orm.reference Id(approved_by)}
 * @property TMSPage $Page {@orm.reference Id(page)} 
 */
class TMSComment extends TNOrmObject {
/**
 * @var int
 * @orm.scalar comment_id
 */	
	public $Id;
	
/**
 * @var string
 * @orm.scalar nickname
 */	
	public $NickName;
	
/**
 * @var string
 * @orm.scalar contents
 */	
	public $CommentText;
	
/**
 * @var date
 * @orm.scalar added
 */	
	public $Added;
	
/**
 * @var date
 * @orm.scalar approved
 */	
	public $Approved;
	
/**
 * @var bool
 * @orm.scalar is_approved
 */	
	public $IsApproved;	
	
/**
 * @var TMSUser
 */	
	protected $_orm_author_;
/**
 * @var TMSUser
 */	
	protected $_orm_approved_by_;
	
/**
 * @var TMSPage
 */	
	protected $_orm_page_;
	
	public function __toString(){
		return $this->CommentText;
	}
	
	public function __get($nm){
		switch ($nm){
			case 'AuthorName':{
				if ($this->_orm_author_)
					return $this->_orm_author_;
				else return $this->NickName;	
			}break;
			default:return parent::__get($nm);break;	
		}
	}
}

/**
 * @author dkrasilnikov@gmail.com
 */
class TMSPageAssociationType extends TEnumeration {
	const MONODIRECTIONAL = 'MDIR';
	const BIDIRECTIONAL = 'BDIR';
	const AGREGATED = 'AGR';
}

/**
 * @author kras
 * @orm.table assoc_class(acid)
 * @orm.key Id
 */
class TMSPageAssociationClass extends TNOrmObject {
/**
 * @var int
 * @orm.scalar acid
 */	
	public $Id;
	
/**
 * @var string
 * @orm.scalar name
 */	
	public $Name;
	
/**
 * @var string
 * @orm.scalar type
 */	
	public $Type;
	
	public function Type(){
		return new TMSPageAssociationType($this->Type);
	}
}

/**
 * @author kras
 * @orm.table page_assoc_classes(page,assoc_class)
 * @orm.key Page
 * @orm.key Class
 * 
 * @property TMSPage $Page {@orm.reference Id(page)}
 * @property TMSPageAssociationClass $Class {@orm.reference Id(assoc_class)}
 */
class TMSPageAssociationClassAssignment extends TNOrmObject {
	protected $_orm_page_;
	
	protected $_orm_class_;
}

/**
 * @author dkrasilnikov@gmail.com
 * @orm.table associated_pages(master_page,detail_page,class)
 * @orm.key MasterPage 
 * @orm.key DetailPage
 * @orm.key Class
 * 
 * @property TMSPage $MasterPage {@orm.reference Id(master_page)}
 * @property TMSPage $DetailPage {@orm.reference Id(detail_page)}
 * @property TMSPageAssociationClass $Class {@orm.reference Id(class)}
 */
class TMSPageAssociation extends TNOrmObject {
/**
 * @var TMSPage
 */	
	protected $_orm_master_page_;
/**
 * @var TMSPage
 */	
	protected $_orm_detail_page_;
/**
 * @var TMSPageAssociationType
 */	
	protected $_orm_class_;
}

/**
 * @author dkrasilnikov@gmail.com
 * @orm.table page(pid)
 * @orm.key Id
 * 
 * @property TMSUser $ModifiedBy {@orm.reference Id(modified_by)}
 * @property TMSShowMode $Mode {@orm.reference Id(mode)}
 * @property TMSComment $Comments {@orm.collection Page(pid)}
 * @property TMSCategory $Categories {@orm.collection TMSCategoryPageAssociation.Category Page(pid)}
 * @property TMSPageImage $Images {@orm.collection Page(page.pid) -s OrderNumber(asc)}
 * @property TMSPageAssociationClass $AssociationClasses {@orm.collection TMSPageAssociationClassAssignment.Class Page(pid)}
 */
class TMSPage extends TNOrmObject {
/**
 * @var int
 * @orm.scalar pid
 */	
	public $Id;
		
/**
 * @var string
 * @orm.scalar lang
 */
	public $Language;
	
/**
 * @var string
 * @orm.scalar title
 */	
	public $Title;
	
/**
 * @var string
 * @orm.scalar slug
 */	
	public $Slug;
		
/**
 * @var string
 * @orm.scalar contents
 */	
	public $PageContents;
	
/**
 * @var string
 * @orm.scalar keywords
 */	
	public $Keywords;
	
/**
 * @var string
 * @orm.scalar description
 */	
	public $Description;
		
/**
 * @var string
 * @orm.scalar snippet
 */	
	public $Snippet;
	
/**
 * @var bool
 * @orm.scalar is_published
 */	
	public $IsPublished;
	
/**
 * @var date
 * @orm.scalar added
 */	
	public $Added;
	
/**
 * @var date
 * @orm.scalar modified
 */	
	public $Modified;
	
/**
 * @var date
 * @orm.scalar published
 */	
	public $Published;
	
/**
 * @var TMSShowMode
 */	
	protected $_orm_mode_;
			
/**
 * @var TMSUser
 */	
	protected $_orm_modified_by_;
	
/**
 * @var TMSComment[]
 */	
	protected $_orm_comments_;
	
/**
 * @var TMSPageImage[]
 */
	protected $_orm_images_;	
	
/**
 * @var TMSCategory[]
 */	
	protected $_orm_categories_;

/**
 * @var TMSPageAssociationClass[]
 */
	protected $_orm_association_classes_;	
	
	public function __toString(){
		return (string)$this->Title;
	}
}

/**
 * @author dkrasilnikov@gmail.com
 * @orm.table page_category(category,page)
 * @orm.key Category 
 * @orm.key Page
 * 
 * @property TMSCategory $Category {@orm.reference Id(category)}
 * @property TMSPage $Page {@orm.reference Id(page)}
 */
class TMSCategoryPageAssociation extends TNOrmObject {
/**
 * @var TMSCategory
 */	
	protected $_orm_category_;
/**
 * @var TMSPage
 */	
	protected $_orm_page_;
}

/**
 * @author dkrasilnikov@gmail.com
 * @orm.table page_image(imid)
 * @orm.key Id
 *
 * @property TMSPage $Page {@orm.reference Id(page)}
 */
class TMSPageImage extends TNOrmObject {
	/**
	 * @var int
	 * @orm.scalar imid
	 */
	public $Id;

	/**
	 * @var int
	 * @orm.scalar ordernum
	 */
	public $OrderNumber;
	/**
	 * @var TMSPage
	 */
	protected $_orm_page_;
	/**
	 * @var string
	 * @orm.scalar description
	 */
	public $Description;

	public function __toString(){
		return (string)$this->Description;
	}
}